package vista;

import modelo.Automata;
import modelo.Edge;
import modelo.Node;
import vista.modelo.VEdge;
import vista.modelo.VNode;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class Drawer {

	public static void drawEdges(Canvas canvas, Paint paint, Automata automata, int xWindow, int yWindow, int windowWidth, int windowHeight) {
		for (Edge e : automata.edges) {
			VEdge edge = (VEdge)e;
			paint.setColor(Color.BLACK);
			paint.setStyle(Paint.Style.STROKE);
			canvas.drawPath(edge.getPath(xWindow, yWindow), paint);
			paint.setStyle(Paint.Style.FILL);
			canvas.drawPath(edge.arrow, paint);
			paint.setColor(Color.WHITE);
			canvas.drawRect(edge.x-10, edge.y-10, edge.x+20, edge.y+20, paint);
			paint.setColor(Color.RED);
			canvas.drawText(edge.inputWordsString, edge.x - edge.inputWordsString.length()*4, edge.y + 8, paint);
		}
	}
	
	public static void drawNodeToJoin(Canvas canvas, Paint paint, VNode toJoin, int xWindow, int yWindow, int windowWidth, int windowHeight) {
		if(toJoin != null) {
			paint.setColor(Color.CYAN);
			paint.setStyle(Paint.Style.FILL);
			int halfRadius = toJoin.radius/2;
			canvas.drawCircle(toJoin.x-halfRadius-xWindow, toJoin.y-halfRadius-yWindow, (int)(toJoin.radius*1.5), paint);
		}
	}
	
	public static void drawNodos(Canvas canvas, Paint paint, Automata automata, int xWindow, int yWindow, int windowWidth, int windowHeight) {

		boolean first = true;
		for (Node n : automata.nodes) {
			VNode nodo = (VNode)n;
			paint.setColor(Color.BLUE);
			paint.setStyle(Paint.Style.FILL);
			int halfRadius = nodo.radius/2;
			canvas.drawCircle(nodo.x-halfRadius-xWindow, nodo.y-halfRadius-yWindow, nodo.radius, paint);
			paint.setColor(Color.WHITE);
			canvas.drawText(nodo.name, nodo.x-xWindow-halfRadius-(nodo.name.length()+1)*5, nodo.y-yWindow-halfRadius+5, paint);
			if(nodo.acceptor) {
				paint.setColor(Color.BLUE);
				paint.setStyle(Paint.Style.STROKE);
				canvas.drawCircle(nodo.x-halfRadius-xWindow, nodo.y-halfRadius-yWindow, (int)(nodo.radius*1.5), paint);
			}
			if(first) {
				first = false;
				paint.setColor(0xFFEF7908);
				paint.setStyle(Paint.Style.STROKE);
				paint.getStrokeWidth();
				paint.setStrokeWidth(5);
				canvas.drawLine(nodo.x-nodo.radius*2-xWindow, nodo.y-nodo.radius-yWindow, nodo.x-nodo.radius-halfRadius-xWindow, nodo.y-halfRadius-yWindow, paint);
				canvas.drawLine(nodo.x-nodo.radius*2-xWindow, nodo.y-yWindow, nodo.x-nodo.radius-halfRadius-xWindow, nodo.y-halfRadius-yWindow, paint);
				paint.setStrokeWidth(0);
			}
		}
	}

}
